/*
 *  Copyright 2019-2025 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.controller.store;


import lombok.RequiredArgsConstructor;

import java.util.List;

import me.zhengjie.annotation.Log;
import me.zhengjie.dao.WareTypeDao;
import me.zhengjie.dao.dto.WareTypeQueryCriteria;
import me.zhengjie.server.WareTypeService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.io.IOException;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
 * @author laoxu
 * @date 2025-06-18
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "WareTypeController")
@RequestMapping("/api/wareType")
public class WareTypeController {

    @Resource
    private WareTypeService wareTypeService;


    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('wareType:list')")
    public void exportWareType(HttpServletResponse response, WareTypeQueryCriteria criteria) throws IOException {
        wareTypeService.download(wareTypeService.queryAll(criteria), response);
    }

    @GetMapping
    @ApiOperation("查询WareTypeController")
    @PreAuthorize("@el.check('wareType:list')")
    public ResponseEntity<PageResult<WareTypeDao>> queryWareType(WareTypeQueryCriteria criteria){
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        return new ResponseEntity<>(wareTypeService.queryAll(criteria,page),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增WareTypeController")
    @ApiOperation("新增WareTypeController")
    @PreAuthorize("@el.check('wareType:add')")
    public ResponseEntity<Object> createWareType(@Validated @RequestBody WareTypeDao resources){
        wareTypeService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改WareTypeController")
    @ApiOperation("修改WareTypeController")
    @PreAuthorize("@el.check('wareType:edit')")
    public ResponseEntity<Object> updateWareType(@Validated @RequestBody WareTypeDao resources){
        wareTypeService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除WareTypeController")
    @ApiOperation("删除WareTypeController")
    @PreAuthorize("@el.check('wareType:del')")
    public ResponseEntity<Object> deleteWareType(@ApiParam(value = "传ID数组[]") @RequestBody List<String> ids) {
        wareTypeService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}